<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('试题列表')" />
</head>
<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="notice-form">
					<div class="select-list">
						<ul>
							<li>
								题库：
								<select name="repoId" id="repoId">
									<option value="">所有</option>
									<option th:each="data : ${repoList}" th:selected="${repoId == data.id}" th:text="${data.title}" th:value="${data.id}"></option>
								</select>
							</li>
							<li>
								题目类型：
								<select name="quType" th:with="type=${@dict.getType('quType')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								题目内容：<input type="text" name="content" autocomplete="off"/>
							</li>							
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
		        <a class="btn btn-success" onclick="add()" shiro:hasPermission="exam:qu:add">
		            <i class="fa fa-plus"></i> 新增
		        </a>
		        <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="exam:qu:edit">
		            <i class="fa fa-edit"></i> 修改
		        </a>
		        <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="exam:qu:remove">
		            <i class="fa fa-remove"></i> 删除
		        </a>
		        <a class="btn btn-info" onclick="importExcel()" shiro:hasPermission="exam:qu:import">
			        <i class="fa fa-upload"></i> 导入
			    </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
	            <table id="bootstrap-table"></table>
	        </div>
    	</div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('exam:qu:edit')}]];
        var removeFlag = [[${@permission.hasPermi('exam:qu:remove')}]];
        var quTypes = [[${@dict.getType('quType')}]];
        var prefix = ctx + "exam/qu";
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "试题",
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : 'id',
					visible: false
				},
				{
					field : 'quType', 
					title : '题目类型',
					formatter: function(value, row, index) {
		            	return $.table.selectDictLabel(quTypes, value);
		            }
				},
				{
					field : 'content', 
					title : '题目内容',
					formatter:function(value, row, index){
						value=value?value:'';
						if(value.length && value.length > 45){
							return "<span title ='"+value+"'>"+value.substring(0,45)+"...</span>"
						}
						return value;
					}
				},
				{
		            field: 'createTime',
		            title: '创建时间'
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        function add(){
        	var repoId = $("#repoId option:selected").val();
        	var url = prefix +"/add";
        	if(repoId != ''){
        		url =url+"?repoId="+repoId
        	}
        	$.modal.open("添加试题", url);
        }
        function importExcel(){
        	var repoId = $("#repoId option:selected").val();
        	var url = prefix +"/importExcel";
        	if(repoId != ''){
        		url =url+"?repoId="+repoId
        	}
        	$.modal.open("导入试题", url);
        }
    </script>
</body>
</html>